from backend.models.base import BaseModel
from backend.database import db

class Device(BaseModel):
    __tablename__ = 'devices'
    
    device_id = db.Column(db.String(100), unique=True, nullable=False)
    device_name = db.Column(db.String(200))
    model = db.Column(db.String(200))
    brand = db.Column(db.String(100))
    os_version = db.Column(db.String(50))
    status = db.Column(db.String(50), default='离线')  # 在线, 离线, 忙碌, 空闲
    ip_address = db.Column(db.String(50))
    port = db.Column(db.Integer)
    battery_level = db.Column(db.Integer, default=0)
    is_usb_connected = db.Column(db.Boolean, default=True)
    current_task_id = db.Column(db.Integer, db.ForeignKey('tasks.id'), nullable=True)
    
    # 关系
    tasks = db.relationship('Task', backref='device', lazy=True)